java list去重

java list去重:
①通过Iterator 的remove方法;
②直接将结果赋值给另一个List;
③用set去重

Talk is cheap,show me your code ~

/**
     * list去重-通过Iterator 的remove方法;
     * @return
     */
    public static  List<String> listRM1(List<String> list) {  
        List<String> listTemp= new ArrayList<String>();  
         Iterator<String> it=list.iterator();  
         while(it.hasNext()){  
          String a=it.next();  
          if(listTemp.contains(a)){  
           it.remove();  
          }  
          else{  
           listTemp.add(a);  
          }  
         }  

        return listTemp;
    }    

/**
     * list去重-直接将结果赋值给另一个List;
     * @return
     */
    public static  List<String> listRM(List<String> list) {  
        List<String> tempList= new ArrayList<String>();  
        for(String i:list){  
            if(!tempList.contains(i)){  
                tempList.add(i);  
            }  
        }  

        return tempList;
    }     

/**
     * list去重-用set去重
     * @return
     */
    public static  List<String> listRM3(List<String> list) {  
        List<String> listTemp= null;  
        HashSet<String> set = new HashSet<String>();
        set.addAll(list);
        listTemp = new ArrayList<String>(set);
        return listTemp;
    }  
生活不止苟且,还有我喜爱的海岸.